package com.ruicar.afs.cloud.afscase.channel.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruicar.afs.cloud.afscase.channel.entity.ChannelVoucherInfo;
import com.ruicar.afs.cloud.afscase.channel.mapper.ChannelVoucherInfoMapper;
import com.ruicar.afs.cloud.afscase.channel.service.ChannelVoucherInfoService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.List;

/**
 * @author infinity
 * @version 1.0
 * @date 2020/7/22 13:58
 */
@Service
@AllArgsConstructor
@Slf4j
public class ChannelVoucherInfoServiceImpl extends ServiceImpl<ChannelVoucherInfoMapper, ChannelVoucherInfo> implements ChannelVoucherInfoService {

    //保存凭证信息
    public Boolean saveVoucher(List<ChannelVoucherInfo> list, String dealerName) {
        if (list == null || !list.isEmpty()) {
            log.error("渠道名称：{},凭证信息为空，不可保存！", dealerName);
        }
        Assert.isTrue(list != null && !list.isEmpty(), "凭证信息为空，不可保存！");
        this.remove(Wrappers.<ChannelVoucherInfo>query().lambda()
                .eq(ChannelVoucherInfo::getChannelId, list.get(0).getChannelId()).eq(ChannelVoucherInfo::getEventId, list.get(0).getEventId()));
        Boolean flag = this.saveBatch(list);
        if (!flag) {
            log.error("渠道名称：{},凭证信息保存失败！", dealerName);
        }
        Assert.isTrue(flag, "凭证信息保存失败！");
        return Boolean.TRUE;
    }


}
